package com.sdsy.util;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
 * Created by yxc on 2018/4/11.
 */
public class EncryptionUtil {


    /**
     * base64编码
     *
     * @param password
     * @return
     */
    public static String getBASE64Encoder(String password) {
        byte[] bytes = password.getBytes();
        BASE64Encoder base64Encoder = new BASE64Encoder();
        String encode_password = base64Encoder.encodeBuffer(bytes);
        System.out.println(encode_password);
        return encode_password;
    }

    /**
     * base64解码
     *
     * @param password
     * @return
     */
    public static String getBASE64Decoder(String password) throws IOException {
        BASE64Decoder base64Decoder = new BASE64Decoder();
        byte[] encode_password = base64Decoder.decodeBuffer(password);
        String str = new String(encode_password);
        System.out.println(str);
        return str;
    }

    public static void main(String[] args) {
        System.out.println(getBASE64Encoder("111111111"));
    }


}
